// 引入api
import { reqCategoryList, reqGetBannerList, reqGetFloorList } from '@/api'


// home模块的小仓库
const state = {
    categoryList: [],
    bannerList: [],
    floorList: []
}
const actions = {
    // 通过api里面的接口函数调用，向服务器发请求，获取数据
    async categoryList({ commit }) {
        let result = await reqCategoryList();
        if (result.code == 200) {
            commit("CATEGORYLIST", result.data)
        }
    },

    async getBannerList({ commit }) {
        // console.log('正在向服务器发送请求');
        let result = await reqGetBannerList();
        if (result.code == 200) {
            commit("GETBANNERLIST", result.data)
        }
    },

    async getFloorList({ commit }) {
        let result = await reqGetFloorList();
        if (result.code == 200) {
            commit("GETFLOORLIST", result.data)
        }
    }
}

const mutations = {
    CATEGORYLIST(state, resultData) {
        state.categoryList = resultData
            // console.log('正在修改state中的数据');
    },

    GETBANNERLIST(state, resultData) {
        state.bannerList = resultData
    },

    GETFLOORLIST(state, resultData) {
        state.floorList = resultData
    },
}

const getters = {}

export default {
    state,
    mutations,
    actions,
    getters
}